/* ************************************************************************

   Copyright: Prince Samuel

   License: MPL

   Authors: Prince Samuel

************************************************************************ */

/*This is a data store. Grabs JSON data from a URL
 * and converts it into qooxdoo model.
 */
qx.Class.define("ohmweb.DataService",
{
  extend : qx.core.Object,
  properties : {
      tree : {
          nullable : true,
          event : "changeTree"
      }

  },
  events: {
    "dataLoaded" : "qx.event.type.Event"
  },
  members : {
      __store : null,

      refreshData : function() {
          if (this.__store == null) {
              var url = "data.json";
              this.__store = new qx.data.store.Json(url);
              this.__store.bind("model", this, "tree");
              this.__store.addListener("loaded", function(){
                  this.fireEvent("dataLoaded");
              }, this);
          } else {
              this.__store.reload();
          }

      }
  }
});

